import { render } from "../../../../hrpub/common/frame";
import { base } from 'nc-lightapp-front';
import { getAppPageConfig } from '../../../../hrpub/common/utils/utils';
const { NCCheckbox } = base;

export default class MainAction {
    constructor(comp) {
        this.comp = comp;
    }

    // appConfig = {
    //     pagecode: '60091060nccloud',
    //     appcode: '60091060'
    // }

    // 获取多语
    getLanguage = () => {
        const { props } = this.comp;
        const {
            dispatch,
            MultiInit
        } = props;

        MultiInit.getMultiLang({
            moduleId: 'gx6008',
            domainName: 'hrtrn',
            callback: (json, status, init) => {
                dispatch({
                    type: 'emp/update',
                    payload: {
                        language: json
                    }
                });
            }
        });
    }

    //获取模板信息
    getTemplate = () => {
        const { props } = this.comp;
        //const {editTable} =props;
        props.createUIDom(this.appConfig, (data) => {
            console.log('wowwow', data)
            data.template = this.initMeta(data.template);
            props.meta.setMeta(data.template);
            props.button.setButtons(data.button);      
            console.log('wow', data.template)
        });
    }

    //初始化模板
    initMeta = (template) => {
        const { props, action } = this.comp;
        const { emp, editTable } = props;

        template['appconfgrid'].items.forEach(item => {
            if(item.attrcode === 'infoset_item_name'){
                item.isSort = false;
            }
            if(item.attrcode === 'entry_card_show_edit'){
                item.isSort = false;
            }
            if(item.attrcode === 'entry_approval'){
                item.isSort = false;
            }
            if(item.attrcode === 'entry_not_null'){
                item.isSort = false;
            }
            if(item.attrcode === 'entry_card_show_notedit'){
                item.isSort = false;
            }
            if(item.attrcode === 'entry_card_notshow'){
                item.isSort = false;
            }
            if(item.attrcode === 'entry_list_show'){
                item.isSort = false;
            }
            if(item.attrcode === 'unentry_card_show_edit'){
                item.isSort = false;
            }
            if(item.attrcode === 'unentry_not_null'){
                item.isSort = false;
            }
            if(item.attrcode === 'unentry_card_show_notedit'){
                item.isSort = false;
            }
            if(item.attrcode === 'unentry_card_notshow'){
                item.isSort = false;
            }
            if(item.attrcode === 'unentry_list_show'){
                item.isSort = false;
            }
            if(item.attrcode === 'manager_card_notshow'){
                item.isSort = false;
            }
            if(item.attrcode === 'manager_list_show'){
                item.isSort = false;
            }
        });
        
        let gridMultiple = {
            ['appconfgrid']: [
                {
                    name: emp.language['gx6008-000230'],//授权状态
                    code: "old",
                    children: ["entry_card_show_edit", "entry_approval", "entry_not_null", "entry_card_show_notedit", "entry_card_notshow"]
                },
                {
                    name: emp.language['gx6008-000230'],//授权状态
                    code: "old1",
                    children: ["unentry_card_show_edit", "unentry_not_null", "unentry_card_show_notedit", "unentry_card_notshow"]
                },
                {
                    name: emp.language['gx6008-000230'],//授权状态
                    code: "old2",
                    children: ["manager_card_notshow"]
                }
            ]
        }
        props.meta.handleMultiple(template, gridMultiple);
        return template
    }

    // 初始化
    didMount = () => {
        if (window.location.href.match('localhost:3006')) {
            window.location.hash = `#/ifr?page=20198162232323`;
        }
        this.appConfig = getAppPageConfig()
        this.getTemplate();
        this.getLanguage();
        this.comp.action.btnAct.initPageButton();
        // 统一订阅事件
        this.subscribe();
    }

    //卸载
    willUnMount = () => {
        this.pubSub.unSubscribe('getMainTableData');
    }

    // 事件订阅部分
    subscribe = () => {
        const { comp: { action }, pubSub } = this;
        pubSub.subscribe('getMainTableData', (...args) => {
            action.tableAct.getMainTableData(...args);
        });
    }

    // 确认查询
    toSearch = () => {
        this.comp.action.tableAct.getMainTableData();
    }
}